# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=tinyxml2

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.0
pkgrel=1
pkgdesc="Simple, small, C++ XML parser that can be easily integrated into other programs (mingw-w64)"
arch=('any')
url="http://www.grinninglizard.com/tinyxml2/index.html"
license=("zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs')
source=(https://github.com/leethomason/tinyxml2/archive/${pkgver}.tar.gz)
md5sums=('6f52e826144ad56ceb7856ec149190a1')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
}

build() {

  [[ -d $srcdir/build-${MINGW_CHOST} ]] && rm -rf $srcdir/build-${MINGW_CHOST}
  mkdir $srcdir/build-${MINGW_CHOST}
  cd $srcdir/build-${MINGW_CHOST}
  
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${pkgdir}${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_STATIC_LIBS:BOOL=ON \
    ../${_realname}-$pkgver
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make install
  
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/tinyxml2.pc
}
